package com.obrempon.credit.market.ui.dialog

import android.content.Context
import android.text.SpannableString
import android.view.LayoutInflater
import android.view.View
import com.obrempon.credit.market.common.CommonDialog
import com.obrempon.credit.market.databinding.ObremponKindTipsDialogBinding
import com.obrempon.credit.market.event.ObremponEventPointType

/**
 * ObremponCredit
 * @Author wwdeng
 * @CreateTime: 2024/11/13 15:41
 * @Annotation：提示dialog
 */
class ObremponTipsDialog: CommonDialog {

    private lateinit var binding: ObremponKindTipsDialogBinding
    private var mCallback: IDialogCallback? = null
    //事件备注
    private var eventRemark = ""

    constructor(context: Context) : super(context) {}
    constructor(context: Context, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    constructor(context: Context, remark: String) : super(context) {
        eventRemark = remark
    }
    constructor(context: Context, remark: String, callback: IDialogCallback?) : super(context) {
        mCallback = callback
        eventRemark = remark
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun takeObremponRootView(): View {
        binding = ObremponKindTipsDialogBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initObremponView() {
    }

    override fun initObremponListener() {
        setOnClickListener(binding.buttonCancel) //取消
        setOnClickListener(binding.buttonConfirm) //ok
    }

    override fun takeObremponData() {
    }

    override fun onObremponViewClick(v: View?) {
        dismiss()
        if(mCallback != null){
            mCallback!!.onClick(v)
        }
    }

    /**
     * 设置埋点备注
     */
    fun addObremponKindTipsEventRemark(remark: String){
        eventRemark = remark
    }

    /**
     * 设置提示图标
     */
    fun setObremponKindTipsIconResource(resId: Int){
        binding.imgKindIcon.setImageResource(resId)
    }

    /**
     * 设置提示title
     */
    fun setObremponKindTipsTitleText(title: String){
        binding.textKindTitle.text = title
    }

    /**
     * 设置提示title
     */
    fun setObremponKindTipsTitleText(title: String, color: Int){
        setObremponKindTipsTitleText(title)
        binding.textKindTitle.setTextColor(color)
    }

    /**
     * 设置提示语
     */
    fun setObremponKindTipsMsgText(tips: String){
        binding.textKindTips.text = tips
    }

    /**
     * 设置提示语
     */
    fun setObremponKindTipsMsgText(spannableString: SpannableString){
        binding.textKindTips.text = spannableString
    }

    /**
     * 设置提示语对齐方式
     */
    fun setObremponKindTipsMsgGravity(gravity: Int){
        binding.textKindTips.gravity = gravity
    }

    /**
     * 设置显示一个按钮或两个按钮
     */
    fun isObremponKindTipsDoubleButton(isDouble: Boolean){
        if (isDouble){//显示两个按钮
            binding.buttonCancel.visibility = View.VISIBLE
            binding.buttonConfirm.visibility = View.VISIBLE
        } else {
            binding.buttonCancel.visibility = View.GONE
            binding.buttonConfirm.visibility = View.VISIBLE
        }
    }

    /**
     * 设置取消文字
     */
    fun setObremponKindTipsButtonCancelText(text: String){
        binding.buttonCancel.text = text
    }

    /**
     * 设置取消按钮背景
     */
    fun setObremponKindTipsButtonCancelBackgroundResource(color: Int){
        binding.buttonCancel.shapeDrawableBuilder.setSolidColor(color).intoBackground()
    }

    /**
     * 设置ok文字
     */
    fun setObremponKintTipsButtonConfirmText(text: String){
        binding.buttonConfirm.text = text
    }

    /**
     * 设置ok按钮背景
     */
    fun setObremponKindTipsButtonConfirmBackgroundResource(color: Int){
        binding.buttonConfirm.shapeDrawableBuilder.setSolidColor(color).intoBackground()
    }

    /**
     * 设置两个按钮背景
     */
    fun setObremponKindTipsButtonDoubleBackgroundResource(cancelColor: Int, okColor: Int){
        binding.buttonCancel.shapeDrawableBuilder.setSolidColor(cancelColor).intoBackground()
        binding.buttonConfirm.shapeDrawableBuilder.setSolidColor(okColor).intoBackground()
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }

    override fun onStart() {
        super.onStart()
        addEventPointRequestAction(ObremponEventPointType.DIALOG.OBREMPON_DIALOG_TIPS_SHOW,eventRemark)
    }

    override fun dismiss() {
        super.dismiss()
        addEventPointRequestAction(ObremponEventPointType.DIALOG.OBREMPON_DIALOG_TIPS_DISMISS,eventRemark)
    }
}